<template>
  <div class="compile">
    <div class="header">
      <span>编辑公司介绍</span>
      <el-button class="button" @click="handleback">返回</el-button>
    </div>
    <!-- 富文本 -->
    <span>公司简介：</span>
    <div style="border: 1px solid #ccc">
      <Toolbar
        style="border-bottom: 1px solid #ccc"
        :editor="editorRef"
        :defaultConfig="toolbarConfig"
        :mode="mode"
      />
      <Editor
        style="height: 500px; overflow-y: hidden"
        v-model="valueHtml"
        :defaultConfig="editorConfig"
        :mode="mode"
        @onCreated="handleCreated"
      />
    </div>
    <el-button type="primary" @click="handleserv">保存</el-button>
  </div>
</template>

<script setup>
import "@wangeditor/editor/dist/css/style.css"; // 引入 css
import { ElMessageBox, ElMessage } from "element-plus";

import { onBeforeUnmount, ref, shallowRef, onMounted } from "vue";
import { Editor, Toolbar } from "@wangeditor/editor-for-vue";
import { useRouter } from "vue-router";
import useAboutStore from "../../../store/aboutuse1";
const store = useAboutStore();
// 编辑器实例，必须用 shallowRef
const editorRef = shallowRef();
const mode = ref();
// 内容 HTML  富文本
const valueHtml = ref("<p>hello</p>");
// 获取内容回显
valueHtml.value = store.introList[0].name;
// 保存
const handleserv = () => {
  store.servIntro(valueHtml.value);
  ElMessage({
    message: "保存成功",
    type: "success",
  });
};
// 菜单与编辑器的配置
const toolbarConfig = {};
const editorConfig = { placeholder: "请输入公司简介..." };
// 组件销毁时，也及时销毁编辑器
onBeforeUnmount(() => {
  const editor = editorRef.value;
  if (editor == null) return;
  editor.destroy();
});
const handleCreated = (editor) => {
  editorRef.value = editor; // 记录 editor 实例，重要！
};
// 反回键
const router = useRouter();
const handleback = () => {
  router.back();
};
</script>

<style lang="less" scoped>
.header {
  width: 100%;
  height: 50px;
  span {
    color: rgb(255, 153, 0);
    font-size: 16px;
    padding-left: 8px;
    font-weight: 800;
  }
  .button {
    float: right;
    background-color: rgb(255, 153, 0);
    color: #fff;
    margin-right: 8px;
  }
}
</style>
